package com.iotteam.androidbase.commen.network;


import com.iotteam.androidbase.commen.utils.MD5;
import com.iotteam.androidbase.commen.utils.PLog;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by lidechen on 4/22/17.
 */

public class NetworkUtils {

    private static final String TAG = "NetworkUtils";

    public static String generateSign(Map<String, String> params){
        StringBuilder sb = new StringBuilder();

        int len = params.size();
        String[] buf = new String[len];
        int index = 0;

        for(Map.Entry<String, String> entry : params.entrySet()){
            buf[index++] = entry.getKey();
        }

        Arrays.sort(buf);

        for(int i=0; i<len; i++){
            sb.append(params.get(buf[i]));
//            if(i == len-1){
//                break;
//            }
            sb.append("|");
        }

        sb.append("bjteam");
        String ret = sb.toString();

        PLog.i(TAG, ret);

        ret = MD5.getMd5(ret).toLowerCase();

        PLog.i(TAG, ret +"  len: "+ret.length());

        //return sb.toString();
        return ret;
    }
}
